#pragma once
#include<string>
#include<cstddef>
#include<boost/date_time/posix_time/posix_time.hpp>
#include<odb/nullable.hxx>
#include<odb/core.hxx>
#pragma db object
class Student
{
    public:
        Student(unsigned long sn,const std::string& name,  unsigned short age, unsigned long classes_id)
            :_name(name), _sn(sn), _age(age), _classes_id(classes_id)
        {
        }
        Student(){}

        void sn(unsigned long sn){_sn = sn;}
        unsigned long sn(){return _sn;}

        void name(const std::string& name){_name = name;}
        std::string name(){return _name;}

        void age(unsigned short age){_age = age;}
        odb::nullable<unsigned short> age(){return _age;}

        void classes_id(unsigned long classes_id){_classes_id = classes_id;}
        unsigned long classes_id(){return _classes_id;}


    private:
    friend class odb::access;
        #pragma db id auto
        unsigned long id;
        #pragma db unique index
        unsigned long _sn;
        std::string _name;
        odb::nullable<unsigned short> _age;
        #pragma db index
        unsigned long _classes_id;
};
#pragma db object
class Classes
{
    public:
        Classes(const std::string& name):_name(name){}
        Classes(){}
    void name(const std::string& name){_name = name;}
        std::string name(){return _name;}

    private :
    friend class odb::access;
        #pragma db id auto
        unsigned long _id;
        std::string _name;
};

//查询所有的学生信息，并显示班级名称
#pragma db view object(Student)\
           object(Classes = classes : Student::_classes_id == classes::_id) \
           query((?))
struct classes_student
{
    #pragma db column(Student::id) 
    unsigned long id;
    #pragma db column(Student::_name)
    std::string name;
    #pragma db column(Student::_sn)
    unsigned long sn;
    #pragma db column(Student::_age)
    odb::nullable<unsigned short> age;
    #pragma db column(classes::_name)
    std::string classes_name;
};

#pragma db view query("select name from Student ")
struct all_name
{
    std::string name;
};